package com.openbravo.pos.util;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.JLabel;

public class ThumbNailBuilder
{
  private Image m_imgdefault;
  private int m_width;
  private int m_height;

  public ThumbNailBuilder(int paramInt1, int paramInt2)
  {
    init(paramInt1, paramInt2, null);
  }

  public ThumbNailBuilder(int paramInt1, int paramInt2, Image paramImage)
  {
    init(paramInt1, paramInt2, paramImage);
  }

  public ThumbNailBuilder(int paramInt1, int paramInt2, String paramString)
  {
    try
    {
      init(paramInt1, paramInt2, ImageIO.read(getClass().getClassLoader().getResourceAsStream(paramString)));
    }
    catch (Exception localException)
    {
      init(paramInt1, paramInt2, null);
    }
  }

  private void init(int paramInt1, int paramInt2, Image paramImage)
  {
    this.m_width = paramInt1;
    this.m_height = paramInt2;
    if (paramImage == null)
      this.m_imgdefault = null;
    else
      this.m_imgdefault = createThumbNail(paramImage);
  }

  public Image getThumbNail(Image paramImage)
  {
    if (paramImage == null)
      return this.m_imgdefault;
    return createThumbNail(paramImage);
  }

  public Image getThumbNailText(Image paramImage, String paramString)
  {
    paramImage = getThumbNail(paramImage);
    BufferedImage localBufferedImage = new BufferedImage(paramImage.getWidth(null), paramImage.getHeight(null), 2);
    Graphics2D localGraphics2D = localBufferedImage.createGraphics();
    JLabel localJLabel = new JLabel();
    localJLabel.setOpaque(false);
    localJLabel.setText(paramString);
    localJLabel.setHorizontalAlignment(0);
    localJLabel.setVerticalAlignment(3);
    Dimension localDimension = localJLabel.getPreferredSize();
    localJLabel.setBounds(0, 0, localBufferedImage.getWidth(), localDimension.height);
    Color localColor1 = new Color(255, 255, 255, 64);
    Color localColor2 = new Color(255, 255, 255, 208);
    GradientPaint localGradientPaint = new GradientPaint(new Point(0, 0), localColor1, new Point(localJLabel.getWidth() / 2, 0), localColor2, true);
    localGraphics2D.drawImage(paramImage, 0, 0, null);
    localGraphics2D.translate(0, localBufferedImage.getHeight() - localJLabel.getHeight());
    localGraphics2D.setPaint(localGradientPaint);
    localGraphics2D.fillRect(0, 0, localBufferedImage.getWidth(), localJLabel.getHeight());
    localJLabel.paint(localGraphics2D);
    localGraphics2D.dispose();
    return localBufferedImage;
  }

  private Image createThumbNail(Image paramImage)
  {
    double d1 = this.m_width / paramImage.getWidth(null);
    double d2 = this.m_height / paramImage.getHeight(null);
    int i;
    int j;
    if (d1 < d2)
    {
      i = this.m_width;
      j = (int)(paramImage.getHeight(null) * d1);
    }
    else
    {
      i = (int)(paramImage.getWidth(null) * d2);
      j = this.m_height;
    }
    int k = paramImage.getWidth(null);
    int m = paramImage.getHeight(null);
    BufferedImage localBufferedImage = null;
    Graphics2D localGraphics2D = null;
    Object localObject = paramImage;
    int n = paramImage.getWidth(null);
    int i1 = paramImage.getHeight(null);
    do
    {
      if (k > i)
      {
        k /= 2;
        if (k < i)
          k = i;
      }
      else
      {
        k = i;
      }
      if (m > j)
      {
        m /= 2;
        if (m < j)
          m = j;
      }
      else
      {
        m = j;
      }
      if (localBufferedImage == null)
      {
        localBufferedImage = new BufferedImage(k, m, 2);
        localGraphics2D = localBufferedImage.createGraphics();
        localGraphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      }
      localGraphics2D.drawImage((Image)localObject, 0, 0, k, m, 0, 0, n, i1, null);
      n = k;
      i1 = m;
      localObject = localBufferedImage;
    }
    while ((k != i) || (m != j));
    localGraphics2D.dispose();
    if ((this.m_width != localBufferedImage.getWidth()) || (this.m_height != localBufferedImage.getHeight()))
    {
      localBufferedImage = new BufferedImage(this.m_width, this.m_height, 2);
      int i2 = this.m_width > i ? (this.m_width - i) / 2 : 0;
      int i3 = this.m_height > j ? (this.m_height - j) / 2 : 0;
      localGraphics2D = localBufferedImage.createGraphics();
      localGraphics2D.drawImage((Image)localObject, i2, i3, i2 + i, i3 + j, 0, 0, i, j, null);
      localGraphics2D.dispose();
      localObject = localBufferedImage;
    }
    return (Image)localObject;
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.util.ThumbNailBuilder
 * JD-Core Version:    0.6.0
 */